<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>龙城物业客户端</title>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  <link rel="stylesheet" href="../../styles/common.css">
  <link rel="stylesheet" href="../../styles/login.css">
  <link rel="stylesheet" href="../../styles/icon/iconfont.css" />
  <style>
    .body{
      min-width: 1366px;
    }
  </style>
</head> 

<body>

  <div class="login" id="login-app">

    <div class="login-box">

      <img src="../../img/intro-bg.jpg" alt="">

      <div class="login-form">

        <el-form ref="loginForm" :model="loginForm" :rules="loginRules" >

          <div class="login-form-title">
            <img src="../../img/logo.png" style="width:139px;height:42px;" alt="" />
          </div>

          <el-form-item prop="name">
            <el-input v-model="loginForm.name" type="text" auto-complete="off" placeholder="姓名" maxlength="20"
              prefix-icon="iconfont icon-user"></el-input>
          </el-form-item>

          <el-form-item prop="telephone">
            <el-input v-model="loginForm.telephone" type="password" placeholder="电话" prefix-icon="iconfont icon-lock" maxlength="20"
              @keyup.enter.native="handleLogin"></el-input>
          </el-form-item>

          <el-form-item style="width:100%;">

            <el-button :loading="loading" class="login-btn" size="medium" type="primary" style="width:100%;"
              @click.native.prevent="handleLogin">
              <span v-if="!loading">登录</span>
              <span v-else>登录中...</span>
            </el-button>

          </el-form-item>

        </el-form>
      </div>
    </div>
  </div>

  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="../../plugins/vue/vue.js"></script>
  <!-- 引入组件库 -->
  <script src="../../plugins/element-ui/index.js"></script>
  <!-- 引入axios -->
  <script src="../../plugins/axios/axios.min.js"></script>

  <script>
    new Vue({
      el: '#login-app',
      data() {
        return {
          loginForm:{
            name: '琪亚娜',
            telephone: '15703542783'
          },
          loading: false
        }
      },
      computed: {
        loginRules() {
          const validateUsername = (rule, value, callback) => {
            if (value.length < 1 ) {
              callback(new Error('请输入姓名'))
            } else {
              callback()
            }
          }
          const validatePassword = (rule, value, callback) => {
            if (value.length !== 11) {
              callback(new Error('手机号输入有误'))
            } else {
              callback()
            }
          }
          return {
            'name': [{ 'validator': validateUsername, 'trigger': 'blur' }],
            'telephone': [{ 'validator': validatePassword, 'trigger': 'blur' }]
          }
        }
      },
      created() {
      },
      methods: {

        //业主登录
        handleLogin() {
          axios({
            url: "http://localhost:8080/owner/login?name=" + this.loginForm.name + '&telephone=' + this.loginForm.telephone,
            method: 'get'
          }).then(resp => {
            if (resp.data.result === true) {
              localStorage.setItem('ownerInfo',JSON.stringify(resp.data.data))
              window.location.href= '../../index.html'
            } else {
              this.$message.error(resp.data.msg)
            }
          });
        }

      }
    })
  </script>
</body>

</html>
